Linux前后端环境配置

docker-ce

https://developer.aliyun.com/mirror/docker-ce

1
2
3
4
5
6
7
8
9
10
11
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
  • mysql (容器)

https://hub.docker.com/_/mysql

1
2
3
4
5
6
7
8
9
10
docker run -itdp 3307:3306  \
--name mysql \
--restart=always \
-e MYSQL_ROOT_PASSWORD=db123456 \
-e TZ=Asia/Shanghai \
-v /data/mysql:/var/lib/mysql \
mysql:5.7 \
--character-set-server=utf8 \
--collation-server=utf8_unicode_ci \
--character-set-client-handshake=FALSE

MYSQL 常见变量
MYSQL_ROOT_PASSWORD
MYSQL_DATABASE
MYSQL_USER, MYSQL_PASSWORD
MYSQL_ALLOW_EMPTY_PASSWORD
MYSQL_RANDOM_ROOT_PASSWORD
MYSQL_ONETIME_PASSWORD
MYSQL_INITDB_SKIP_TZINFO

  • redis (容器)

https://hub.docker.com/_/redis

1
2
3
4
5
6
7
docker run -itdp 6379:6379 \
--name redis \
--privileged=true \
--restart=always \
-v /data/redis/data:/data \
redis:latest \
--requirepass "redisPassword" # 镜像内部命令

注意:**–requirepass** 参数是redis参数要放在镜像的后面

  • nginx (容器)

https://hub.docker.com/_/nginx

1
2
3
4
5
docker run -idtp 80:80 \
--name nginx \
--restart=always \
-v /data/nginx:/usr/share/nginx/html \
nginx:latest

jdk

https://www.oracle.com/java/technologies/downloads/#java8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@quanlook ~]# ls
jdk-8u261-linux-x64.tar.gz
[root@quanlook ~]# tar -xzf jdk-8u261-linux-x64.tar.gz -C /usr/local/src/
[root@quanlook ~]# ls /usr/local/src/
jdk1.8.0_261
[root@quanlook ~]# vim /etc/profile

export JAVA_HOME=/usr/local/src/jdk1.8.0_261
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

[root@quanlook ~]# source /etc/profile
[root@quanlook ~]# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
[root@quanlook ~]#

nodejs

node 版本管理器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 安装
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# git 镜像加速 安装
# Github地址:https://github.com/nvm-sh/nvm.git
# 国内加速:https://github.com.cnpmjs.org/nvm-sh/nvm.git
[root@quanlook ~]# mkdir /usr/local/src/{nvm,node}
[root@quanlook ~]# ll /usr/local/src/
total 12
drwxr-xr-x 8 10143 10143 4096 Jun 18 2020 jdk1.8.0_261
drwxr-xr-x 2 root root 4096 Nov 16 21:02 node
drwxr-xr-x 2 root root 4096 Nov 16 21:06 nvm
[root@quanlook ~]# git clone https://github.com.cnpmjs.org/nvm-sh/nvm.git /usr/local/src/nvm
Cloning into '/usr/local/src/nvm'...
remote: Enumerating objects: 8526, done.
remote: Counting objects: 100% (269/269), done.
remote: Compressing objects: 100% (165/165), done.
remote: Total 8526 (delta 146), reused 198 (delta 100), pack-reused 8257
Receiving objects: 100% (8526/8526), 3.16 MiB | 1.16 MiB/s, done.
Resolving deltas: 100% (5371/5371), done.

[root@quanlook ~]# cat>>/etc/profile.d/nvm.sh<<EOF
# 导出NVM_DIR 环境变量,让nvm 安装node到该目录
export NVM_DIR=/usr/local/src/node
# 执行nvm 的命令, 激活nvm 到系统shell 中
source /usr/local/src/nvm/nvm.sh
EOF

# npm 配置淘宝镜像源
[root@quanlook ~]# npm config set registry https://registry.npmjs.org/

[root@quanlook ~]# nvm install 16.10.0
Downloading and installing node v16.10.0...
Downloading https://nodejs.org/dist/v16.10.0/node-v16.10.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.10.0 (npm v7.24.0)
[root@quanlook ~]# nvm list
v16.4.0
-> v16.10.0
default -> 16.4.0 (-> v16.4.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v17.1.0) (default)
stable -> 17.1 (-> v17.1.0) (default)
lts/* -> lts/gallium (-> v16.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.7 (-> N/A)
lts/fermium -> v14.18.1 (-> N/A)
lts/gallium -> v16.13.0
[root@quanlook ~]# nvm use v16.4.0
Now using node v16.4.0 (npm v7.18.1)
[root@quanlook ~]# node --version
v16.4.0
[root@quanlook ~]#